/*!
    \copyright  Copyright (c) 2020 - 2023 Qualcomm Technologies International, Ltd.\n
                All Rights Reserved.\n
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file       
    \ingroup    connection_manager
    \brief      The sending of events from the Connection Manager using the Event Bus
*/

#include "connection_manager_event_send.h"

#include "conn_acl_status_channel_event_spec.h"
#include "event_bus_publish.h"

#include <logging.h>

static void conManager_EventBusSend(conn_acl_status_event_t event, void * data, uint16 data_size)
{
    EventBus_Publish(EVENT_BUS_CHANNEL_CONN_ACL_STATUS, event, data, data_size);
}

void ConManager_EventSendAclConnected(const tp_bdaddr * tpaddr)
{
    CONN_ACL_CONNECTED_T event = {0};
    event.tpaddr = *tpaddr;
    event.status = hci_success;
    
    DEBUG_LOG("ConManager_EventSendAclConnected");
    
    conManager_EventBusSend(CONN_ACL_CONNECTED, &event, sizeof(CONN_ACL_CONNECTED_T));
}

void ConManager_EventSendAclDisconnected(const tp_bdaddr * tpaddr, uint16 status)
{
    CONN_ACL_DISCONNECTED_T event = {0};
    event.tpaddr = *tpaddr;
    event.status = status;
    
    DEBUG_LOG("ConManager_EventSendAclDisconnected");
    
    conManager_EventBusSend(CONN_ACL_DISCONNECTED, &event, sizeof(CONN_ACL_DISCONNECTED_T));
}

void ConManager_EventSendAclConnecting(const tp_bdaddr * tpaddr)
{
    CONN_ACL_CONNECTING_T event = {0};
    event.tpaddr = *tpaddr;
    event.status = hci_success;
    
    DEBUG_LOG("ConManager_EventSendAclConnecting");
    
    conManager_EventBusSend(CONN_ACL_CONNECTING, &event, sizeof(CONN_ACL_CONNECTING_T));
}

void ConManager_EventSendAclDisconnecting(const tp_bdaddr * tpaddr)
{
    CONN_ACL_DISCONNECTING_T event = {0};
    event.tpaddr = *tpaddr;
    event.status = hci_success;
    
    DEBUG_LOG("ConManager_EventSendAclDisconnecting");
    
    conManager_EventBusSend(CONN_ACL_DISCONNECTING, &event, sizeof(CONN_ACL_DISCONNECTING_T));
}

void ConManager_EventSendAclConnectingFailure(const tp_bdaddr * tpaddr)
{
    CONN_ACL_CONNECTING_FAILURE_T event = {0};
    event.tpaddr = *tpaddr;
    event.status = hci_error_unspecified;
    
    DEBUG_LOG("ConManager_EventSendAclConnectingFailure");
    
    conManager_EventBusSend(CONN_ACL_CONNECTING_FAILURE, &event, sizeof(CONN_ACL_CONNECTING_FAILURE_T));
}

void ConManager_EventSendAclBargeInRequest(const tp_bdaddr * tpaddr)
{
    CONN_ACL_BARGE_IN_REQUEST_T event = {0};
    event.tpaddr = *tpaddr;

    DEBUG_LOG("ConManager_EventSendAclBargeInRequest");

    conManager_EventBusSend(CONN_ACL_BARGE_IN_REQUEST, &event, sizeof(CONN_ACL_BARGE_IN_REQUEST_T));
}

